/**
 * 
 */
(function(root,factory){
	root["JSUtils"] = new factory();
	root["basePath"] = JSUtils.getBasePath();
})(this,function(module){
	var factory = function(){
		this.version = '1.0';
	};
	var fn = factory.prototype;
	fn.getBasePath = function(){
	    var curWwwPath = window.document.location.href;
	    var pathName = window.document.location.pathname;
	    var pos = curWwwPath.indexOf(pathName);
	    var localhostPath = curWwwPath.substring(0, pos);
	    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
	    var basePath=localhostPath+projectName+"/";
	    return basePath;
	}
	fn.loadAjax = function(param){
		var params = $.extend(true,{},module["ajaxDefault"],param);
		if(params["async"] === false){
			var resulet = null;
			params["success"]  = function(datas){
				resulet = datas;
			};
			console.log(params);
			$.ajax(params);
			return resulet;
		}else{
			$.ajax(params);
		}
	}
	/**
	 * 获取地址栏参数Val
	 * @param name 参数名称
	 * @returns
	 */
	fn.GetQueryString = function (name)
	{
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if(r!=null)return  unescape(r[2]); return null;
	}

	/**
	 * 获取一个随机的uuid
	 * @returns
	 */
	fn.uuid = function() {
		var s = [];
		var hexDigits = "0123456789abcdef";
		for (var i = 0; i < 36; i++) {
			s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
		}
		s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
		s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
		s[8] = s[13] = s[18] = s[23] = "-";

		var uuid = s.join("");
		return uuid;
	}
	
	return factory;
}({	ajaxDefault:{
		type:"POST",
		url:"",
		data:null,
		dataType:"json",
		success:null,
		error:function(XMLHttpRequest, textStatus, errorThrown){
			console.log("XMLHttpRequest:"+XMLHttpRequest+",errorThrown:"+errorThrown);
		}
	}
}))